package com.futvan.z.framework.tags;

import com.futvan.z.framework.core.SuperTag;
import com.futvan.z.framework.core.z;
import com.futvan.z.system.zform.z_form_table;
import com.futvan.z.system.zform.z_form_table_button;
import com.futvan.z.system.zform.z_form_table_column;

import javax.servlet.jsp.JspException;
import java.util.HashMap;
import java.util.List;

public class ListPage extends SuperTag{
	private List<HashMap<String,String>> list;
	private HashMap<String,String> parameter;
	private String userid;

	@Override
	public int doEndTag() throws JspException {

		StringBuffer out_html = new StringBuffer();

		try {
			z_form_table table = z.tables.get(parameter.get("tableId"));
			List<z_form_table_column> columnList = table.getZ_form_table_column_list();
			List<z_form_table_button> buttonList = table.getZ_form_table_button_list();

			//创建功能代码
			String pageType = "list";
			if("1".equals(table.getList_display_style())) {
				pageType = "list_card";
			}

			out_html.append("<div data-options=\"region:'north'\" class=\"border-top-0 border-right-0 border-left-0\" style=\"height:"+getNorthHeight(parameter.get("is_mobile"))+"px;overflow:hidden;\">").append("\r\n");
			//创建按钮行
			CreateFunctionHtml(buttonList,out_html,pageType,userid,table,parameter);

			//创建ListSearchBoxForm + 设置快速查询框信息
			CreateListQueryForm(out_html,columnList,pageType,table,parameter);

			out_html.append("</div>").append("\r\n");

			//创建查询域名
			CreateSelectHtml("list",parameter,out_html,table,columnList);

			//创建表格代码
			out_html.append("<div data-options=\"region:'center',border:false\">").append("\r\n");


			if("1".equals(table.getList_display_style())) {
				//列表显示为卡片组
				CreateCardGroup(out_html,columnList,parameter,table,userid,list);
			}else {
				//列表显示为数据表格
				CreateTableHtml(out_html,columnList,list,parameter);
			}
			out_html.append("</div>").append("\r\n");

			//创建分页代码
			out_html.append("<div data-options=\"region:'south',border:false\" style=\"height:40px;overflow:hidden\">").append("\r\n");
			CreatePagingHtml("list",parameter,out_html);
			out_html.append("</div>").append("\r\n");


			//创建JS方法
			CreateJS(out_html,pageType,table,parameter,userid);

			//添加初始HTML代码
			if(z.isNotNull(table.getList_ready_html())) {
				out_html.append(table.getList_ready_html()).append("\r\n");
			}

		} catch (Exception e) {
			throw new JspException("ListPage:自定义标签构建错误："+e.getMessage());
		}

		//输出HTML
		outHTML(out_html.toString());
		return super.doEndTag();
	}


	


	public List<HashMap<String, String>> getList() {
		return list;
	}

	public void setList(List<HashMap<String, String>> list) {
		this.list = list;
	}

	public HashMap<String, String> getParameter() {
		return parameter;
	}

	public void setParameter(HashMap<String, String> parameter) {
		this.parameter = parameter;
	}
	public String getUserid() {
		return userid;
	}
	public void setUserid(String userid) {
		this.userid = userid;
	}

}
